
let id = 0

export class Dep {//每个属性都分配一个dep  dep可以存放watcher  watcher中还要存放dep
  constructor() {
    this.id = id++
    this.subs = [] //存放watcher 
  }
  depend () {
    // Dep.target  
    if (Dep.target) {
      Dep.target.addDep(this)
    }
  }
  addSub (watcher) {
    this.subs.push(watcher)
  }
  notify () {
    this.subs.forEach(watcher => {
      // 重新走 vm._update(vm._render)
      watcher.update()
    })
  }

}
Dep.target = null

export function pushTarget (watcher) {
  Dep.target = watcher
}
export function popTarget () {
  Dep.target = null
}